package com.obixlabs.commons.util;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;

public class LockUtil {

	public static void acquireReadLock(ReadWriteLock lock) 
	{ acquireLock(lock.readLock());}

	public static void releaseReadLock(ReadWriteLock lock) 
	{ releaseLock(lock.readLock()); }
	
	public static void acquireWriteLock(ReadWriteLock lock) 
	{ acquireLock(lock.writeLock());}

	public static void releaseWriteLock(ReadWriteLock lock) 
	{ releaseLock(lock.writeLock()); }	
	
	public static void acquireLock(Lock lock) 
	{ lock.lock(); }

	public static void releaseLock(Lock lock) 
	{ lock.unlock(); }
	
	public static void upgradeReadLock(ReadWriteLock lock) {
		releaseReadLock(lock);
		acquireWriteLock(lock);
	}

	public static void downgradeWriteLock(ReadWriteLock lock) {
		acquireReadLock(lock);
		releaseWriteLock(lock);
	}	
}
